package com.wuxb.util.disruptor.main;

import com.lmax.disruptor.EventTranslator;

import java.util.Random;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Product implements EventTranslator<Person> {
    private int num;
    private Lock lock = new ReentrantLock();

    private Random random=new Random();

    public Product(int num){
        this.num = num;
    }
    @Override
    public void translateTo(Person person, long l) {
        try {
            lock.lock();
            System.out.println(person.toString());
            person.setId(random.nextInt(100));
        } finally {
            lock.unlock();
        }
    }
}
